package com.um.jdy.platform.device.controller;



import com.um.jdy.common.device.entity.po.BsbLog;
import com.um.jdy.platform.device.entity.dto.EbLogExportDTO;
import com.um.jdy.platform.device.entity.dto.EbLogPageParams;
import com.um.jdy.platform.device.manger.BsbLogManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import com.um.springboot.starter.orm.params.PageParams;
import com.um.springboot.starter.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 控制器：换电柜日志
 */
@RestController
@RequestMapping("/api/v1/cms/device/bsb_log")
@Api(tags = "设备管理", description = "换电柜日志")
@ApiPermission("bsb_log")
@TokenRequired
@Validated
public class BsbLogController extends BaseController<BsbLogManager> {

    /**
     * 分页查询充电桩日志
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Response<Page<BsbLog>> getPage(@RequestBody EbLogPageParams params){
        if(StringUtil.isEmpty(params.getCode())){
            return Response.failed("设备编码不能为空！");
        }

        PageParams pageParams = params.toPageParams(
                new String[]{"cmd","code"},
                new String[]{"cmd","code"});
        pageParams.getCondition().put("orderby","auto_id desc");
        return manager.getPage(pageParams,params.getCreateTime());
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

    /**
     * 导出设备日志
     *
     * @param params
     * @return
     */
    @ApiPermission("export")
    @ApiOperation("导出设备日志")
    @PostMapping("/export_page")
    public Response exportPage(@RequestBody EbLogExportDTO params){
        if(StringUtil.isEmpty(params.getCode())){
            return Response.failed("设备编码不能为空！");
        }

        ExportParams exportParams = params.toExportParams(
                new String[]{"cmd","code"},
                new String[]{"cmd","code"});
        exportParams.getCondition().put("orderby","auto_id desc");
        return manager.exportPage(exportParams,params.getCreateTime());
    }
}
